/*
 * Created on 2006-8-8
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package other;

import java.util.HashMap;
import java.util.Map;

import com.powerunion.datacollection.report.excelreport.IQueryDataListener;
import com.powerunion.datacollection.report.excelreport.ReportEntry;
import com.powerunion.datacollection.report.excelreport.config.ReportConfig;
import com.powerunion.datacollection.report.excelreport.datasource.BaseDataSource;
import com.powerunion.datacollection.report.excelreport.datasource.IDataSource;
import com.powerunion.datacollection.report.excelreport.datasource.StaticDataSource;



/**
 * @author juny
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class GroupDemo extends ReportEntry {
    private static final String[] pro = new String[]{
            "上海市",
            "北京市",
            "江西省",
            "湖南省",
            "广东省",
            "新疆自治区",
            "安徽省",
            "福建省",
            "浙江省",
            "江苏省"
    };
    private static final String[][] products = new String[][]{
            {"VE192-途安2.0手动档5座舒","1000000478","1000000"},
            {"VC122-PASSAT领驭2.0自动标准型","1000000479","2200000"},
            {"VT262-POLO三厢1.6自动舒适","1000000480","1886000"},
            {"VE192-途安2.0手动档5座舒适型","1000000481","2200000"},
            {"VE292-途安1.8T自动档5座豪华型","1000000484","1400000"},
            {"VLAL2-桑塔纳3000 1.8L手动档","1000000486","1300000"},
            {"VLAJ2-桑塔纳3000 2.0L手动档","1000000487","1200000"},
            {"VQBD2-桑塔纳3000 2.0L自动档","1000000488","1100000"},
            {"VE202-途安2.0L手动舒适","1000000489","11100000"},
            {"VQBE2-桑塔纳3000 1.8自动舒适型","1000000490","2480000"}
    	};
    public boolean execute(
            ReportConfig reportConfig, //报表配置参数对象
            Map dataSources, 		   //报表数据源
            Map params				   //传入参数。
            )throws Exception{   
        int radom = 0;
        int radomp = 0;
        int randomProduct = 0, number = 0;
        Map product1 = new HashMap(10);
        StaticDataSource ds = (StaticDataSource)dataSources.get("groupDs");
        if(ds == null){
            return false;
        }
        
        String province = "";
        try{
        for(int i=0; i<10; i++){
            province = pro[i];
            //随机生成几条记录
            radom = (int)Math.abs(Math.random()*10);
            for(int j=0; j<radom; j++){
                radomp = (int)Math.abs((Math.random()*10));
                randomProduct = (int)Math.abs(Math.random()*10 - 1);
                if(null == product1.get(String.valueOf(randomProduct))){
                    product1.put(String.valueOf(randomProduct),"");
                    for(int k=0; k<radomp; k++){
	                    ds.addField("province", province);
	        	        ds.addField("sub1", products[randomProduct][0]);
	        	        ds.addField("sub2", products[randomProduct][1]);
	        	        number = (int)Math.abs(Math.random()*100);
	        	        ds.addField("sub3", new Integer(number));
	        	        ds.addField("sub4", new Integer(products[randomProduct][2]));
	        	        ds.addRecord();
                    }
                }
            }
        }
        ds.setQueryDataListener(new IQueryDataListener(){
            public boolean beforeQuery(IDataSource dataSource) {
                BaseDataSource baseDataSource = (BaseDataSource)dataSource;
                baseDataSource.moveToFirst();
                baseDataSource.setFieldValue("province", "ni hao 修改了值");
                return false;
            }
            public void afterQuery(IDataSource dataSource){
                
            }
        });
        }catch(Exception e){
            throw e;
        }
        return true;
    }

}
